// pages/distribut/order_commission/order_commission.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var common = require('../../../../utils/common.js');
var util = require('../../../../utils/util.js');
import LoadMore from '../../../../utils/LoadMore.js'
var load = new LoadMore;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
    url:setting.url,
		tablist: [{
				count: 0,
				order_sn: '11111111111',
				head_pic: "../../../../images/touxiang.png",
				nickname: "小秋刀鱼",
				order_create_time: "15:45:12",
				time: "18.88"
			},
			{
				count: 0,
				order_sn: '11111111111',
				head_pic: "../../../../images/touxiang.png",
				nickname: "小秋刀鱼",
				order_create_time: "15:45:12",
				time: "18.88"
			},
			{
				count: 0,
				order_sn: '11111111111',
				head_pic: "../../../../images/touxiang.png",
				nickname: "小秋刀鱼",
				order_create_time: "15:45:12",
				time: "18.88"
			},
			{
				count: 0,
				order_sn: '11111111111',
				head_pic: "../../../../images/touxiang.png",
				nickname: "小秋刀鱼",
				order_create_time: "15:45:12",
				time: "18.88"
			},
			{
				count: 0,
				order_sn: '11111111111',
				head_pic: "../../../../images/touxiang.png",
				nickname: "小秋刀鱼",
				order_create_time: "15:45:12",
				time: "18.88"
			}
		],
		time: app.getym(),
		currentdate: {
			hao: new Date().getDate(),
			zj: new Date().getDay(),
			datedq: app.globalData.parseTime(new Date(), '{y}-{m}-{d}'),
			nianyuer: app.globalData.parseTime(new Date(), '{y}年{m}月{d}日'),
		},
		currentlist: app.getDate(new Date()),
		zlist: ['周日', '周一', '周二', '周三', '周四', '周五', '周六', ],
		list: [],
		info: {},
		currentTab: 1,
		page: 1,
		one: 0,
		two: 0,
		three: 0,
		currentPage: 1,
	},
	itemclick(e) {
		this.setData({
			time: app.globalData.parseTime(e.detail, '{y}年{m}月'),
			currentlist: app.getDate(e.detail),
			currentdate: {
				hao: new Date(e.detail).getDate(),
				zj: new Date(e.detail).getDay(),
				datedq: app.globalData.parseTime(e.detail, '{y}-{m}-{d}'),
				nianyuer: app.globalData.parseTime(e.detail, '{y}年{m}月{d}日')
			},
			list: [],
			currentPage: 1
		})
		this.getlist()
	},
	itemclick1(e) {
		this.setData({
			currentdate: e.detail,
			list: [],
			currentPage: 1
		})
		this.getlist()
	},

	// 获取今日订单明细
	getlist() {
		let that = this
		request.get('/api/shop/getCommissionLog', {
			data: {
				page_no: that.data.currentPage,
				day_time: that.data.currentdate.datedq,
				page_size: 10,
				commission_type: 1,
				add_type: 0
			},
			success: function(res) {
				if (res.data.status == 1 && res.data.result.data.length != 0) {
					that.data.currentPage++;
          let datalist = that.data.list.concat(res.data.result.data || [])
          if(datalist.length>0){
            for(var index in datalist){
              datalist[index].order_create_time=util.formatTime(datalist[index].order_create_time,'Y/M/D h:m:s');
            }
          }
					that.setData({
						list: datalist,
						currentTab: res.data.result.count
					})
				}

			}
		});
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		if (options.date) {
			this.itemclick({
				detail: options.date
			})
		}
		// this.getlist()
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {
		if (Math.ceil(this.data.currentTab) > this.data.currentPage) {
			this.getTeamList();
		}
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})